home *** CD-ROM | disk | FTP | other *** search
/ T&A 2 the Maxx 3 / T and A 2 The Maxx Number 3.iso / viewers / unixview / xgiftar.z / xgiftar / image.h < prev    next >
C/C++ Source or Header  |  1991-05-20  |  5KB  |  207 lines

  1. /* image.h:
  2.  *
  3.  * portable image type declarations
  4.  *
  5.  * jim frost 10.02.89
  6.  *
  7.  * Copyright 1989 Jim Frost.  See included file "copyright.h" for complete
  8.  * copyright information.
  9.  */
  10.  
  11. #include "copyright.h"
  12. #include <stdio.h>
  13.  
  14. #if defined(SYSV) || defined(VMS)
  15. #include <string.h>
  16. #ifndef index /* some SysV's do this for you */
  17. #define index strchr
  18. #endif
  19. #ifndef rindex
  20. #define rindex strrchr
  21. #endif
  22. #ifndef HAS_MEMCPY
  23. #define HAS_MEMCPY
  24. #endif
  25. #else /* !SYSV && !VMS */
  26. #include <strings.h>
  27. #endif /* !SYSV && !VMS */
  28.  
  29. #ifdef VMS
  30. #define R_OK 4
  31. #define NO_UNCOMPRESS
  32. #endif
  33.  
  34. #ifdef HAS_MEMCPY
  35.  
  36. /* equate bcopy w/ memcpy and bzero w/ memset where appropriate.
  37.  */
  38.  
  39. #ifndef bcopy
  40. #define bcopy(P1,P2,N) memcpy((char *)(P2),(char *)(P1),(N))
  41. #endif
  42. #ifndef bzero
  43. #define bzero(P,N) memset((P),'\0',(N))
  44. #endif
  45. #endif /* HAS_MEMCPY */
  46.  
  47. typedef unsigned long  Pixel;     /* what X thinks a pixel is */
  48. typedef unsigned short Intensity; /* what X thinks an RGB intensity is */
  49. typedef unsigned char  byte;      /* byte type */
  50.  
  51. struct cache {
  52.   int           len;
  53.   char          buf[BUFSIZ];
  54.   struct cache *next;
  55. };
  56.  
  57. typedef struct {
  58.   unsigned int  type;     /* ZIO file type */
  59.   unsigned int  nocache;  /* true if caching has been disabled */
  60.   FILE         *stream;   /* file input stream */
  61.   char         *filename; /* filename */
  62.   struct cache *data;     /* data cache */
  63.   struct cache *dataptr;  /* ptr to current cache block */
  64.   int           bufptr;   /* ptr within current cache block */
  65. } ZFILE;
  66.  
  67. #define ZSTANDARD 0 /* standard file */
  68. #define ZPIPE     1 /* file is a pipe (ie uncompress) */
  69. #define ZSTDIN    2 /* file is stdin */
  70.  
  71. typedef struct rgbmap {
  72.   unsigned int  size;       /* size of RGB map */
  73.   unsigned int  used;       /* number of colors used in RGB map */
  74.   unsigned int  compressed; /* image uses colormap fully */
  75.   Intensity    *red;        /* color values in X style */
  76.   Intensity    *green;
  77.   Intensity    *blue;
  78. } RGBMap;
  79.  
  80. /* image structure
  81.  */
  82.  
  83. typedef struct {
  84.   char         *title;  /* name of image */
  85.   unsigned int  type;   /* type of image */
  86.   RGBMap        rgb;    /* RGB map of image if IRGB type */
  87.   unsigned int  width;  /* width of image in pixels */
  88.   unsigned int  height; /* height of image in pixels */
  89.   unsigned int  depth;  /* depth of image in bits if IRGB type */
  90.   unsigned int  pixlen; /* length of pixel if IRGB type */
  91.   byte         *data;   /* data rounded to full byte for each row */
  92. } Image;
  93.  
  94. #define IBITMAP 0 /* image is a bitmap */
  95. #define IRGB    1 /* image is RGB */
  96. #define ITRUE   2 /* image is true color */
  97.  
  98. #define BITMAPP(IMAGE) ((IMAGE)->type == IBITMAP)
  99. #define RGBP(IMAGE)    ((IMAGE)->type == IRGB)
  100. #define TRUEP(IMAGE)   ((IMAGE)->type == ITRUE)
  101.  
  102. #define TRUE_RED(PIXVAL)   (((PIXVAL) & 0xff0000) >> 16)
  103. #define TRUE_GREEN(PIXVAL) (((PIXVAL) & 0xff00) >> 8)
  104. #define TRUE_BLUE(PIXVAL)  ((PIXVAL) & 0xff)
  105. #define RGB_TO_TRUE(R,G,B) \
  106.   ((((R) & 0xff00) << 8) | ((G) & 0xff00) | ((B) >> 8))
  107.  
  108. /* special case 1-byte transfers so they're inline
  109.  */
  110.  
  111. #define memToVal(PTR,LEN)    ((LEN) == 1 ? (unsigned long)(*(PTR)) : \
  112.                   doMemToVal(PTR,LEN))
  113. #define memToValLSB(PTR,LEN) ((LEN) == 1 ? (unsigned long)(*(PTR)) : \
  114.                   doMemToValLSB(PTR,LEN))
  115. #define valToMem(VAL,PTR,LEN)    ((LEN) == 1 ? \
  116.                   (unsigned long)(*(PTR) = (byte)(VAL)) : \
  117.                   doValToMem(VAL,PTR,LEN))
  118. #define valToMemLSB(VAL,PTR,LEN) ((LEN) == 1 ? \
  119.                   (unsigned long)(*(PTR) = (byte)(VAL)) : \
  120.                   (int)doValToMemLSB(VAL,PTR,LEN))
  121.  
  122. /* SUPPRESS 558 */
  123.  
  124. /* function declarations
  125.  */
  126.  
  127. Image *clip(); /* clip.c */
  128.  
  129. void brighten(); /* bright.c */
  130. void equalize();
  131. void gray();
  132. Image *normalize();
  133.  
  134. void compress(); /* compress.c */
  135.  
  136. Image *dither(); /* dither.c */
  137.  
  138. void fill(); /* fill.c */
  139.  
  140. void fold(); /* fold.c */
  141.  
  142. Image *halftone(); /* halftone.c */
  143.  
  144. Image *loadImage(); /* imagetypes.c */
  145. void   identifyImage();
  146. void   goodImage();
  147.  
  148. Image *merge(); /* merge.c */
  149.  
  150. extern unsigned long DepthToColorsTable[]; /* new.c */
  151. unsigned long colorsToDepth();
  152. char  *dupString();
  153. Image *newBitImage();
  154. Image *newRGBImage();
  155. Image *newTrueImage();
  156. void   freeImage();
  157. void   freeImageData();
  158. void   newRGBMapData();
  159. void   freeRGBMapData();
  160. byte  *lcalloc();
  161. byte  *lmalloc();
  162. void   lfree();
  163.  
  164. #define depthToColors(n) DepthToColorsTable[((n) < 32 ? (n) : 32)]
  165.  
  166. Image *reduce(); /* reduce.c */
  167. Image *expand();
  168.  
  169. Image *rotate(); /* rotate.c */
  170.  
  171. Image *smooth(); /* smooth.c */
  172.  
  173. /* doMemToVal and doMemToValLSB used to be void type but some compilers
  174.  * (particularly the 4.1.1 SunOS compiler) couldn't handle the
  175.  * (void)(thing= value) conversion used in the macros.
  176.  */
  177.  
  178. unsigned long doMemToVal(); /* value.c */
  179. unsigned long doValToMem();
  180. unsigned long doMemToValLSB();
  181. unsigned long doValToMemLSB();
  182. void          flipBits();
  183.  
  184. ZFILE *zopen();
  185. int    zread();
  186. void   zreset();
  187.  
  188. ZFILE *zopen(); /* zio.c */
  189. int    zread();
  190. int    zgetc();
  191. char  *zgets();
  192. void   zclose();
  193. void   znocache();
  194. void   zreset();
  195.  
  196. Image *zoom(); /* zoom.c */
  197.  
  198. /* this returns the (approximate) intensity of an RGB triple
  199.  */
  200.  
  201. #define colorIntensity(R,G,B) \
  202.   (RedIntensity[(R) >> 8] + GreenIntensity[(G) >> 8] + BlueIntensity[(B) >> 8])
  203.  
  204. extern unsigned short RedIntensity[];
  205. extern unsigned short GreenIntensity[];
  206. extern unsigned short BlueIntensity[];
  207.